# This PowerShell script was released under the Ms-PL license
# http://www.opensource.org/licenses/ms-pl.html
# This script was originally intended for use with Microsoft Dynamics AX 2009
# and maintained and distributed as a project on CodePlex
# http://dynamicsaxbuild.codeplex.com

param(
	[string] $AXCOMPILEHTML,
	[string] $AXCOMPILEXML
	)

$XMLSTART = "<AxaptaCompilerOutput>"
$XMLEND = "</AxaptaCompilerOutput>"

"<?xml version=`"1.0`" encoding=`"UTF-8`"?>" | out-file -Encoding "UTF8" $AXCOMPILEXML

$html = Get-Content -LiteralPath $AXCOMPILEHTML
ForEach ($line in $html)
{
	if ($xmlBlock -eq $true)
	{
		if (($line | Select-String -SimpleMatch $XMLEND))
		{
			$line | out-file -Encoding "UTF8" -append $AXCOMPILEXML
			$xmlBlock = $false
			Break;
		}
		$line | out-file -Encoding "UTF8" -append $AXCOMPILEXML
	}
	elseif (($line | Select-String -SimpleMatch $XMLSTART))
	{
		$line | out-file -Encoding "UTF8" -append $AXCOMPILEXML
		$xmlBlock = $true
	}
}
